package 找出整型数组中占比超过一半的数.src.v1.main;

public class Main {
    public static int solution(int[] array) {
        int count = 0;
        Integer candidate = null;

        for (int num : array) {
            if (count == 0) {
                candidate = num;
            }
            count += (num == candidate) ? 1 : -1;
        }

        return candidate;
    }

    public static void main(String[] args) {
        // Add your test cases here

        System.out.println(solution(new int[] { 1, 3, 8, 2, 3, 1, 3, 3, 3 }) == 3);
    }
}
